package com.sunfeng.netty.heima.bytebuf;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;

import static com.sunfeng.netty.heima.utils.NettyUtils.log;


/**
 * @ClassName Demo02
 * @Description TODO
 * @Author 孙峰
 * @Date 2022/10/25 15:53
 */
public class Demo02 {
    public static void main(String[] args) {
        ByteBuf buffer = ByteBufAllocator.DEFAULT.buffer(10);
        buffer.writeBytes(new byte[]{1, 2, 3, 4});
        log(buffer);
        for (int i = 0; i < 9; i++) {
            buffer.writeInt(1);
        }
        log(buffer);
        //读过的内容，就属于废弃部分了，再读只能读那些尚未读取的部分
        System.out.println(buffer.readByte());
        System.out.println(buffer.readByte());
        System.out.println(buffer.readByte());
        System.out.println(buffer.readByte());
        System.out.println(buffer.readByte());
        log(buffer);
    }
}
